#'
#' Uniqueness locations of individuals by various methods
#' 
#' 
#' @usage
#' uniqueness(com)
#' uniqueness(pop)
#' 
#' 
#' @param com a community object
#' @param pop a population object
#' 
#' @details
#' 
#' #TODO  right now only random noise method were implimented
#' 
#' @return
#' a population or community object with nonoverlap individuals
#'
#'@export
uniqueness=function(x,method="random_noise",...){
  UseMethod("uniqueness")
}

uniqueness.numeric=function(x,oids,...){
  sd_x=mean(x,na.rm=T)*0.001 #add a niose with 0.001*mean(x) standard deviation
  for(i in 1:length(oids)){
    oid=oids[[i]]
    x[oid]=x[oid]+rnorm(length(oid),sd=sd_x)  #this operation may let individuals outside the plot
  }
  return(x)
}

uniqueness.community=function(com,method="random_noise"){
  oids=get_overlapped(com)
  if(length(oids)==0) return(com)
  
  if(method=="random_noise"){
    deli=unlist(lapply(oids,function(x) sample(x,1)))
  }
  #browser()
  return(com[-deli])
}

uniqueness.population=function(pop,method="random_noise"){
  oids=get_overlapped(pop)
  if(length(oids)==0) return(pop)
  
  if(method=="random_noise"){
    deli=unlist(lapply(oids,function(x) sample(x,1)))
  }
  return(pop[-deli])
}